﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace GrouponDesktop.ListadoEstadistico
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            dateInicio.Value = DateTime.Parse(ConfigurationSettings.AppSettings["actualDate"].ToString());
            dateFin.Value = DateTime.Parse(ConfigurationSettings.AppSettings["actualDate"].ToString()).AddMonths(6);
        }

        private void btnCargar_Click(object sender, EventArgs e)
        {
            try
            {
                

                if (cboTipo.SelectedItem == "Listado GiftCards")
                {
                    DGV.Columns.Clear();
                    BAL.ListEstadisticoBAL proxy = new BAL.ListEstadisticoBAL();
                    List<DAL.Entities.ListGiftCardsEntity> list = new List<DAL.Entities.ListGiftCardsEntity>();
                    list = proxy.ListGiftCards(dateInicio.Value, dateFin.Value);
                    DGV.DataSource = list;
                }
                else if (cboTipo.SelectedItem == "Listado Devoluciones")
                {
                    DGV.Columns.Clear();
                    BAL.ListEstadisticoBAL proxy = new BAL.ListEstadisticoBAL();
                    List<DAL.Entities.ListDevolucionesEntity> list = new List<DAL.Entities.ListDevolucionesEntity>();
                    list = proxy.ListDevoluciones(dateInicio.Value, dateFin.Value);
                    DGV.DataSource = list;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ha ocurrido un error: " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }   
        }

        private void dateInicio_ValueChanged(object sender, EventArgs e)
        {
            DateTime hoy = new DateTime();
            DateTime fin = new DateTime();
            hoy = dateInicio.Value;
            fin = hoy.AddMonths(6);
            dateFin.Value = fin;
        }
    }
}
